<template>
  <div class="profile-page">
    <header class="header">
      <div class="container">
        <div class="logo">
          <h1>小米商城</h1>
        </div>
        <nav class="nav">
          <router-link to="/">首页</router-link>
          <router-link to="/products">商品</router-link>
          <router-link to="/profile">个人中心</router-link>
        </nav>
      </div>
    </header>

    <div class="container">
      <h2 class="page-title">个人中心</h2>
      <div class="profile-content">
        <el-card>
          <template #header>
            <span>用户信息</span>
          </template>
          <div v-if="!userStore.isLoggedIn">
            <p>您还未登录</p>
            <el-button type="primary" @click="handleLogin">登录</el-button>
          </div>
          <div v-else>
            <p>用户名: {{ userStore.user?.username || 'admin' }}</p>
            <el-button @click="handleLogout">退出登录</el-button>
          </div>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from '../stores'
import { ElMessage } from 'element-plus'

const router = useRouter()
const userStore = useUserStore()

const handleLogin = () => {
  // 简单模拟登录
  userStore.login({ username: 'admin', id: 1 })
  ElMessage.success('登录成功')
}

const handleLogout = () => {
  userStore.logout()
  ElMessage.success('已退出登录')
}
</script>

<style scoped>
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.header {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  padding: 15px 0;
  margin-bottom: 40px;
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo h1 {
  color: #E02E24;
  font-size: 24px;
}

.nav {
  display: flex;
  gap: 30px;
}

.nav a {
  text-decoration: none;
  color: #333;
}

.nav a.router-link-active {
  color: #E02E24;
}

.page-title {
  font-size: 32px;
  margin-bottom: 40px;
}

.profile-content {
  max-width: 600px;
}
</style>

